from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination

#1，自定义分页对象
from rest_framework.response import Response


class MyPageNumberPagination(PageNumberPagination):
    #1.可以在前端制定页面数据大小
    page_query_param = 'pagesize'
    #限制页面最大数
    #2.重写相应值的方法
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('page', self.page.number),
            ('pages', self.page.paginator.num_pages),
            ('lists', data)
        ]))
